/**
 * Copyright (c) 2024 watereyes
 * workflow is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.common.web.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.koron.ebs.mybatis.EnvSource;

import com.koron.common.bean.StaffBean;
import com.koron.common.web.bean.DepartmentBean;
import com.koron.common.web.bean.DepartmentTreeBean;

@EnvSource("_default")
public interface DepartmentMapper {
	@Select("select tbltree.seq,tbltree.parentmask,tbldepartment.* from tbltree \n" + 
			"inner join tbldepartment on tbltree.foreignkey=tbldepartment.id \n" + 
			"inner join (\n" + 
			"	select tbltree.* from tbltree \n" + 
			"where type = 65536 and seq =#{id}) a on (tbltree.seq & ~((1 << (62 - a.parentMask-a.mask))-1)) = a.seq")
	public List<DepartmentTreeBean> getDescendantByParentId(@Param("id") Long id);
	@Select("select tbltree.seq,tbltree.parentmask,tbldepartment.* from tbltree \n" + 
			"inner join tbldepartment on tbltree.foreignkey=tbldepartment.id \n" + 
			"where (#{seq} & ~((1 << (62 - parentmask-mask))-1)) = seq\n" + 
			"order by seq\n")
	public List<DepartmentTreeBean> getPathById(@Param("seq") Long seq);
	@Select("select a.*,b.name as departmentname,b.code as departmentCode from tblstaff a left join tbldepartment b on a.departmentCode = b.code where b.code = #{department}")
	public List<StaffBean> getStaffOfDep(@Param("department")String code);
	@Select("select a.*,b.name as departmentname,b.code as departmentCode  from tblstaff a left join tbldepartment b on a.departmentCode = b.code")
	public List<StaffBean> getStaffInfo();
	@Select("select code,name as department from tbldepartment")
	public List<DepartmentTreeBean> getDepartmentInfo();
	@Delete("DELETE FROM tbldepartment")
	int deleteAll();
	@Select("select tbltree.seq,tbltree.parentmask,tbldepartment.* from tbltree \n" + 
			"inner join tbldepartment on tbltree.foreignkey=tbldepartment.id \n" + 
			"where flag = #{flag} order by seq ")
	public List<DepartmentTreeBean> getDepartmentInfoByFlag(@Param("flag") int flag);
	@Select("select * from tbldepartment where code = #{code}")
	public DepartmentTreeBean getDepartmentInfoByCode(@Param("code") String waterCode);
	public int batchInsertDepartment(List<DepartmentBean> list);
	public int updateDepartment(DepartmentBean bean);

}